package com.utils.demo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author Devin
 * @program my-java
 * @description
 * @date 2024-02-29 15:50
 **/
public class BitTest1 {
    public static void main(String[] args) {
//        long setV = BitUtil.setBitStatusInLong(0, 0);
//        System.out.println(setV);
//        int getV = BitUtil.getBitStatusInLong(1, 1);
//        System.out.println(getV);

//        binarySearch();

//        System.out.println("++++:" + getScriptType(101));
//
//        System.out.println("取余数：" + 0 % 7);

//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
//        int startTimestamp = 0;
//        int endTimestamp = 0;
//        try {
//            startTimestamp = (int) (sdf.parse("2024.06.03").getTime() / 1000L);
//            endTimestamp = (int) (sdf.parse("2024.06.10").getTime() / 1000L);
//        } catch (ParseException e) {
////            logger.error("InfiniteGiftBoxService initServiceCfg parseTime error! ");
//            e.printStackTrace();
//        }
//        System.out.println(startTimestamp);
//        System.out.println(endTimestamp);
//        int day = 24 * 3600;
//        System.out.println((endTimestamp - startTimestamp) /day );

//        System.out.println(Arrays.toString("1,2".trim().split(",")));


//        System.out.println(getBitStatus(6, 3));
//        String picUrl2 = "http:";
//        System.out.println(isNumerStr(picUrl2));

        System.out.println(getBitStatus(0,0) == 1);

    }


    public static int getScriptType(int gameModel) {
        return (gameModel << 16 >> 24) == 0 ? gameModel >> 16 : gameModel << 16 >> 24;
    }

    /**
     * 获取某个状态位
     * @param num
     * @param bit
     * @return
     */
    public static int getBitStatus(int num, int bit)
    {
        return ((num >> bit) & 1);
    }



    public static void binarySearch() {
        List<Integer> sequence = new ArrayList<>();
        sequence.add(1);
        sequence.add(3);
        sequence.add(5);
        sequence.add(6);
        sequence.add(19);

        int target = 5;
        int index = Collections.binarySearch(sequence, target);

        if (index >= 0 && index < sequence.size() - 1) {
            int next = sequence.get(index + 1);
            System.out.println("给定数的后一个数是：" + next);
        } else {
            System.out.println("没有找到后一个数");
        }
    }
//    public int getPrizeBit(int day) {
//        day = day > 0 ? day - 1 : day;
//        return BitUtil.getBitStatusInLong(prize, day);
//    }
//
//    public void setPrizeBit(int day) {
//        day = day > 0 ? day - 1 : day;
//        this.prize = BitUtil.setBitStatusInLong(prize, day);
//    }

    public static boolean isNumerStr(String str) {
        if (str == null || str.isEmpty()) {
            return false;
        }

        str = str.trim();
        if (str.isEmpty()) {
            return false;
        }

        try {
            Integer.parseInt(str);
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }
}
